<?php
class home extends CI_controller{

	function __construct(){
		parent::__construct();

		$this->load->helper('bara_helper');
		$this->load->library('bara_lib');
		$this->load->model('hit_counter');

		//$flang = 'home';
		$this->load->model('modul/login_member_model','',TRUE);
        $this->load->helper('url');
        $this->load->library(array('form_validation','session'));

		$this->lang->load('menu_top', $this->bara_lib->language_name());

		$this->load->model('modul/model_menu');

		$this->load->model('modul/about_model');
		$this->load->model('modul/article_model');
		$this->load->model('modul/sosmed_model');
		
	}

	function index(){

		/*login home
		if($this->session->userdata('logged_in'))
        {
            $session_data = $this->session->userdata('logged_in');
            $data['username'] = $session_data['udername'];
            $data['id'] = $session_data['id_member'];
            $this->load->view('layout/'. $this->bara_lib->theme() .'/menu', $data);
        } else {
        //If no session, redirect to login page
            redirect('frontend/'. $this->bara_lib->theme() .'/modul/login_member/login_member', 'refresh');
        }
*/

		//menu
		$data['text_home'] = $this->lang->line('text_home');
		$data['text_corporate'] = $this->lang->line('text_corporate');
		$data['text_contact'] = $this->lang->line('text_contact');
		$data['text_site'] = $this->lang->line('text_site');

		$ip = $_SERVER['REMOTE_ADDR'];

		$date = date("Y-m-d H:i:s");
		$this->hit_counter->count($ip, $date);
		

		//$data['contents'] = array('slide_home','news_home');
		$data['contents'] = array('slider_banner','about_home','wisata_home','article_home','testimonial_home');

		$data['contents_sidebar'] = array();

		foreach ($data['contents'] as $key => $val_contents) {
			include APPPATH."controllers/modul/$val_contents.php";

			${$val_contents} = new $val_contents();

			$data[$val_contents] = ${$val_contents}->index();
		}

		foreach ($data['contents_sidebar'] as $key => $val_contents_sidebar) {
			include APPPATH."controllers/modul/$val_contents_sidebar.php";

			${$val_contents_sidebar} = new $val_contents_sidebar();

			$data[$val_contents_sidebar] = ${$val_contents_sidebar}->index();
		}

		//menu
		$data['get_menus'] = $this->model_menu->get_menu($this->bara_lib->language());

		// sosmed
		$data['gets_facebook'] = $this->sosmed_model->get_sosmed('facebook');
		$data['gets_twitter'] = $this->sosmed_model->get_sosmed('twitter');
		$data['gets_sosmed'] = $this->sosmed_model->get_sosmed_all();

		//footer
		$data['gets_about_footer'] = $this->about_model->get_about('about_us',$this->bara_lib->language());
		$data['get_articles_footer'] = $this->article_model->get_article($this->bara_lib->language(),3,0);
		//end footer

		$data['head'] = 'layout/'. $this->bara_lib->theme() .'/head';
		$data['menu'] = 'layout/'. $this->bara_lib->theme() .'/menu';
		$data['footer'] = 'layout/'. $this->bara_lib->theme() .'/footer';
		$this->load->view('layout/'. $this->bara_lib->theme() .'/home', $data);	
	}

	function set_language(){
		
		$array = array(
			'language' =>  $this->uri->segment(3),
			'language_name' =>  $this->uri->segment(4),
		);
		$this->session->set_userdata($array);

		$base = $this->uri->segment(5);

		if($this->uri->segment(6)) $base .= "/".$this->uri->segment(6);
		if($this->uri->segment(7)) $base .= "/".$this->uri->segment(7);
		if($this->uri->segment(8)) $base .= "/".$this->uri->segment(8);
		if($this->uri->segment(9)) $base .= "/".$this->uri->segment(9);
		if($this->uri->segment(10)) $base .= "/".$this->uri->segment(10);

		redirect($base);
	}


}
?>